/*
 * @Author: Lijin
 * @Date: 2024-09-19 13:56:33
 * @LastEditors: Lijin
 * @LastEditTime: 2024-09-19 16:19:39
 * @FilePath: \huawei\index.js
 * @Description:
 *
 * Copyright (c) 2024 by 18323406700, All Rights Reserved.
 */
const axios = require("axios");
const moment = require("moment");

const init = async () => {
  let timer = setInterval(() => {
    axios({
      method: "post",
      url: "https://www.vmall.com/order/createcart.json",
      headers: {
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
        Connection: "keep-alive",
        "Content-Length": "1023",
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        Cookie: "rnpersonalurlweb=https%3A%2F%2Fwww.vmall.com%2Fportal%2Fpersonal%2Findex.html%3FpageId%3D401001097; callAB=1; HWWAFSESID=c24b3ca625fd981d87; HWWAFSESTIME=1726735076508; deviceid=906b80ce1d1a214e851a32a14ab32b7b; TID=906b80ce1d1a214e851a32a14ab32b7b; showAds=true; euid=aaa59259871849882bbe597c7711d98b569cbfade00f4f47; CSRF-TOKEN=D3099DA01D6F14F2A91F73F301775D3384CDCBACD452CBC54D24A0B431381B15; isFirstLogin=1; aliToken=; isGroupUser=false; ageGroupFlag=0; optBanding=0; weChatInfo=false; ac_loNa=176****7405; ac_lel=; ac_lmi=; ac_lus=1; ac_lgc=0; ac_ltp=0; ac_li=true; isVpro=0; ac_cp=1500721829297|1500721912154|1599634375481; rush_info=30086000813254398_1726735142_SEC073B55242B4478CBC2F01FEAE0C2303C143C884F80B8B45EC59FC20173ECD5CF; rush_ext=30086000813254398_1_0_1726735142_SEC80D80071B0E73715BD599C1D3EEB92D462163FD92AC33883FA6004E62BE7F36E; uid=30086000813254398; user=176****7405; hasphone=1; displayName=h**********; isAuthCust=false; isAuthByUid=true; recommendflag=true; sdevid=782207c41ab8e64bdb49ae4efb19e1b9ca94769b; salePortal=1; hasSigned=1; device_data=*2k94EVAM1OpzDmDWmETSjTD2NYNNQPJNZMkYAMUJdLUhDwG3X1T0jySz2xz1jjlMYdJYbJNRMMNZT0j4TOclEcZAJYZMtY4h1ylji0hipO3wi3oyyumzm3l0IMYdEbYZAJZkFMdIgbMUAbZFYMMUYMLIUYOA4M4zmxtmjzkDjzljTuwST2rEjwziC9oTCxxDjjxDfQFMkYElV0VQxRUAlM944Ug0FJQEGhxmjz3z32LZIPMVAZMQZXTTjz2VTjzWjj22CGTSjyHTTWz13NYRJOcMQMdlINYVMNPRZOb1ZMVIUecMtZKEUNZGT12jn21WmhwGjUzTEGwG2yujEu122wwDC22DTJDNJMNbNYNMYbZZQVKMMRZMJbYYTxhDz5zWDjlAJccIIMOckOZJlzh1z4h2vlmulyyIlyyump50lgPIJad0YON9RMNM0MeRUZY15Ybl5MJxJVbUUMRUThwzmzlmDjhSmoyiTw0ETvtCSkwSz39nj3hjjhIGQ0ZINNRIRkFZAdF1tNVYF0ZlNwxTmxhjW5wmmZdPIZOMMQMOFNmDTTjWTTDjDUkjDTSmy2TDzGTqlUMMJgZNZJJMIdbOVlNNkpJPl9MbNVJJINZZUGxymDzh2jxNGXvuyF0l2EDymFyySGu52D4nTj5vDVMJJMMYMJJOMeLJKJMaNMNNNMN4WjiynzkwmWwYEdINhEzkx0wsCwymwiWNcMYPQJcMAb1cYSJcFlj2z13uGp2MEhj9jzDimk0kU0ZEIlUFgMGym4TkXQ==",
        CsrfToken:
          "D3099DA01D6F14F2A91F73F301775D3384CDCBACD452CBC54D24A0B431381B15",
        Host: "www.vmall.com",
        Origin: "https://www.vmall.com",
        Referer: "https://www.vmall.com/order/nowConfirmcart",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-origin",
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
        "X-E2E-Trace":
          "e2eId=page#rn_product#1#d029492d47309a626351205392b634f4;spanId=0288799a6e7a732e2d9d5867b62cfa1a",
        "X-Requested-With": "XMLHttpRequest",
        "sec-ch-ua":
          '"Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": '"Windows"',
      },
      data: {
        o2oInfo: "",
        carModel: "",
        vSceneActivityCode: "",
        usingVoucher: "false",
        rushActivityId: "",
        buttonMode: "",
        consigneeAddressId: "221422261",
        orderReq:
          '[{"itemId":"2601010506008","qty":1,"itemType":"S0","gifts":[],"subOrderItemReqArgs":[]}]',

        //商品id是 refreshSbomCacheInfo 的
        couponCodeList: "",
        deliveryMethod: "1",
        couponCode: "",
        usePointFlag: "true",
        usePetalFlag: "false",
        interestOrder: "",
        msgCode: "",
        challenge: "",
        geeValidateUUID: "",
        validate: "",
        secCode: "",
        seqNo: "",
        type: "",
        orderType: "0",
        tenantId: "",
        sourcePortal: "",
        state: "0",
        shopCodes: "VMALL-HUAWEIDEVICE|",
        "effectiveListVMALL-HUAWEIDEVICE": "61|62",
        "uneffectiveListVMALL-HUAWEIDEVICE": "",
        "titleTypeVMALL-HUAWEIDEVICE": "61",
        "invoiceTitleVMALL-HUAWEIDEVICE": "个人",
        "taxpayerIdentityNumVMALL-HUAWEIDEVICE": "",
        "vatInvoiceJsonVMALL-HUAWEIDEVICE": "",
        "vatInvoiceCompanyVMALL-HUAWEIDEVICE": "",
        "vatInvoiceDeliveryJsonVMALL-HUAWEIDEVICE": "",
        carReqInfo: "",
        CsrfToken:
          "D3099DA01D6F14F2A91F73F301775D3384CDCBACD452CBC54D24A0B431381B15",
        appointDelMsg: '{"VMALL-HUAWEIDEVICE":""}',
        usingCouponCodes: "",
        lastSelectedCouponCode: "",
        usingPointNum: "5",
      },
    })
      .then((res) => {
        //返回的数据乱码
        // console.log(res);
        console.log(JSON.stringify(res.data));
        console.log("-----------------------");
        if (res.data.success) {
          clearInterval(timer);
        }

        // debugger;
      })
      .catch((er) => {
        try {
          // console.log(er)
          console.log(er.response.data);
        } catch (error) {}
        //    debugger
        clearInterval(timer);
      });
  }, 200);
};

let t = "2024-09-19 16:14:00"; //开始时间
let times = new Date(t).getTime();
console.log(times);

/**
 *  2022-06-19T04:03:50.378Z  -500
    2022-06-19T04:05:50.743Z  -200
    2022-06-19T04:09:50.891Z  -100
    2022-06-19T04:07:11.282Z  
 
 */
let js = setInterval(() => {
  if (new Date().getTime() >= times - 300) {
    console.log("开始执行");
    console.log(new Date().getTime());
    init();

    setTimeout(() => {
      clearInterval(js);
    }, 200);
  }

  console.log(
    `目标时间:${t},当前时间${moment(new Date().getTime()).format(
      "YYYY-MM-DD HH:mm:ss"
    )}`
  );
}, 100);
